package com.hamster.crmpre.web;

import com.hamster.crmpre.pojo.AffiliatesProgramConfig;
import com.hamster.crmpre.pojo.Employee;
import com.hamster.crmpre.pojo.ProjectAlliance;
import com.hamster.crmpre.service.EmployeeService;
import com.hamster.crmpre.service.FranchiseProjectsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author ：Lizhipeng
 * @date ：Created in 2019/12/31 10:31
 * @description：加盟项目控制
 * @modified By：
 * @version: 1.0
 */
@RestController
@RequestMapping("franchiseProjects")
public class FranchiseProjectsController {
    @Autowired
    private EmployeeService employeeService;
    @Autowired
    private FranchiseProjectsService franchiseProjectsService;

    /**
     * 获取项目加盟
     * @return 加盟项目
     */
    @GetMapping("get")
    public ResponseEntity<List<AffiliatesProgramConfig>> franchiseProjects(){
        List<AffiliatesProgramConfig> affiliatesProgramConfigs =  franchiseProjectsService.get();
        return ResponseEntity.ok(affiliatesProgramConfigs);
    }

    /**
     * 加一条MessageAlliance的数据(项目加盟的数据)同时生成消息
     * @param projectAlliance
     */
    @PostMapping("determine")
    @Transactional
    public void franchiseProjectsDetermine(@RequestBody ProjectAlliance projectAlliance){
        franchiseProjectsService.insert(projectAlliance);
        franchiseProjectsService.messageAdd(projectAlliance);
    }

    /**
     * 获取员工select下拉框
     * @return
     */
    @GetMapping("listEmployee")
    public ResponseEntity<List<Employee>> listEmployee(){
        List<Employee> list = employeeService.listEmployee();
        return ResponseEntity.ok(list);
    }

    /**
     * 分栏 获取项目加盟列表
     * @return
     */
    @GetMapping("listAffiliatesProgram")
    public ResponseEntity<List<Map<String,Object>>> listAffiliatesProgram(@RequestParam(required = false) String name){
        List<Map<String,Object>> list =  franchiseProjectsService.listAffiliatesProgram(name);
        return ResponseEntity.ok(list);
    }


}
